package com.ahcloud.edas.rocketmq.core.application.checker;

import com.ahcloud.edas.common.exception.BizException;
import com.ahcloud.edas.common.util.CollectionUtils;
import com.ahcloud.edas.rocketmq.core.domain.topic.form.TopicAddForm;
import com.ahcloud.edas.rocketmq.core.domain.topic.form.TopicUpdateForm;
import com.ahcloud.edas.rocketmq.core.infrastructure.constant.RmqRetCodeEnum;

import java.util.List;

/**
 * @program: edas
 * @description:
 * @author: YuKai Fan
 * @create: 2024/5/16 11:07
 **/
public class RmqTopicChecker {

    public static void checkTopic(TopicAddForm form) {
        checkTopicBase(form.getReadQueueNum(), form.getWriteQueueNum());
    }

    public static void checkTopic(TopicUpdateForm form) {
        checkTopicBase(form.getReadQueueNum(), form.getWriteQueueNum());
    }


    private static void checkTopicBase(Integer readQueueNum, Integer writeQueueNum) {
        if (readQueueNum > writeQueueNum) {
            throw new BizException(RmqRetCodeEnum.CREATED_TOPIC_FAILED_READNUM_MUST_WRITENUM);
        }
    }
}
